package com.eastcom.bm.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.eastcom.bm.atom.Atom_CalendarItem;
import com.eastcom.bm.dao.AbstractDAO;
import com.eastcom.bm.dao.ICalendarItemDao;
import com.eastcom.common.db.JDBCTemplate;
import com.eastcom.common.db.ResultData;


public class CalendarItemDao extends AbstractDAO implements ICalendarItemDao {

	public List<Atom_CalendarItem> getAllCalendarItems() throws Exception {
		try{
			List<Atom_CalendarItem> results=new ArrayList<Atom_CalendarItem>();
			
			String sql="select i.* from QA_CALENDARITEM i";
	        ResultData rd=JDBCTemplate.executeSQLQuery(sql, JDBCTemplate.PROPAGATION_NEVER, false, false);
			while(rd.next()){
				Atom_CalendarItem calendarItem=new Atom_CalendarItem();
				calendarItem.setUuid(rd.getString("UUID"));
				calendarItem.setPolicyUUID(rd.getString("POLICY_UUID"));
				calendarItem.setSpecialDate(rd.getDate("SPECIAL_DATE"));
				calendarItem.setSpecialDateName(rd.getString("SPECIALDATENAME"));
				calendarItem.setSpecialWorkDate("0".equals(rd.getString("SPECIALWORKDATE"))?false:true);
				calendarItem.setHour0("0".equals(rd.getString("HOUR0"))?false:true);
				calendarItem.setHour1("0".equals(rd.getString("HOUR1"))?false:true);
				calendarItem.setHour2("0".equals(rd.getString("HOUR2"))?false:true);
				calendarItem.setHour3("0".equals(rd.getString("HOUR3"))?false:true);
				calendarItem.setHour4("0".equals(rd.getString("HOUR4"))?false:true);
				calendarItem.setHour5("0".equals(rd.getString("HOUR5"))?false:true);
				calendarItem.setHour6("0".equals(rd.getString("HOUR6"))?false:true);
				calendarItem.setHour7("0".equals(rd.getString("HOUR7"))?false:true);
				calendarItem.setHour8("0".equals(rd.getString("HOUR8"))?false:true);
				calendarItem.setHour9("0".equals(rd.getString("HOUR9"))?false:true);
				calendarItem.setHour10("0".equals(rd.getString("HOUR10"))?false:true);
				calendarItem.setHour11("0".equals(rd.getString("HOUR11"))?false:true);
				calendarItem.setHour12("0".equals(rd.getString("HOUR12"))?false:true);
				calendarItem.setHour13("0".equals(rd.getString("HOUR13"))?false:true);
				calendarItem.setHour14("0".equals(rd.getString("HOUR14"))?false:true);
				calendarItem.setHour15("0".equals(rd.getString("HOUR15"))?false:true);
				calendarItem.setHour16("0".equals(rd.getString("HOUR16"))?false:true);
				calendarItem.setHour17("0".equals(rd.getString("HOUR17"))?false:true);
				calendarItem.setHour18("0".equals(rd.getString("HOUR18"))?false:true);
				calendarItem.setHour19("0".equals(rd.getString("HOUR19"))?false:true);
				calendarItem.setHour20("0".equals(rd.getString("HOUR20"))?false:true);
				calendarItem.setHour21("0".equals(rd.getString("HOUR21"))?false:true);
				calendarItem.setHour22("0".equals(rd.getString("HOUR22"))?false:true);
				calendarItem.setHour23("0".equals(rd.getString("HOUR23"))?false:true);
				results.add(calendarItem);
			}
			
			return results;
		}
		catch(Exception e){
			throw e;
		}
	}

	public List<Atom_CalendarItem> selectCalendarItemByPolicyUUID(String policyUUID) throws Exception {
		try{
			List<Atom_CalendarItem> results=new ArrayList<Atom_CalendarItem>();
			
			String sql="select i.* from QA_CALENDARITEM i where i.policy_uuid='"+policyUUID+"'";
	        ResultData rd=JDBCTemplate.executeSQLQuery(sql, JDBCTemplate.PROPAGATION_NEVER, false, false);
			while(rd.next()){
				Atom_CalendarItem calendarItem=new Atom_CalendarItem();
				calendarItem.setUuid(rd.getString("UUID"));
				calendarItem.setPolicyUUID(rd.getString("POLICY_UUID"));
				calendarItem.setSpecialDate(rd.getDate("SPECIAL_DATE"));
				calendarItem.setSpecialDateName(rd.getString("SPECIALDATENAME"));
				calendarItem.setSpecialWorkDate("0".equals(rd.getString("SPECIALWORKDATE"))?false:true);
				calendarItem.setHour0("0".equals(rd.getString("HOUR0"))?false:true);
				calendarItem.setHour1("0".equals(rd.getString("HOUR1"))?false:true);
				calendarItem.setHour2("0".equals(rd.getString("HOUR2"))?false:true);
				calendarItem.setHour3("0".equals(rd.getString("HOUR3"))?false:true);
				calendarItem.setHour4("0".equals(rd.getString("HOUR4"))?false:true);
				calendarItem.setHour5("0".equals(rd.getString("HOUR5"))?false:true);
				calendarItem.setHour6("0".equals(rd.getString("HOUR6"))?false:true);
				calendarItem.setHour7("0".equals(rd.getString("HOUR7"))?false:true);
				calendarItem.setHour8("0".equals(rd.getString("HOUR8"))?false:true);
				calendarItem.setHour9("0".equals(rd.getString("HOUR9"))?false:true);
				calendarItem.setHour10("0".equals(rd.getString("HOUR10"))?false:true);
				calendarItem.setHour11("0".equals(rd.getString("HOUR11"))?false:true);
				calendarItem.setHour12("0".equals(rd.getString("HOUR12"))?false:true);
				calendarItem.setHour13("0".equals(rd.getString("HOUR13"))?false:true);
				calendarItem.setHour14("0".equals(rd.getString("HOUR14"))?false:true);
				calendarItem.setHour15("0".equals(rd.getString("HOUR15"))?false:true);
				calendarItem.setHour16("0".equals(rd.getString("HOUR16"))?false:true);
				calendarItem.setHour17("0".equals(rd.getString("HOUR17"))?false:true);
				calendarItem.setHour18("0".equals(rd.getString("HOUR18"))?false:true);
				calendarItem.setHour19("0".equals(rd.getString("HOUR19"))?false:true);
				calendarItem.setHour20("0".equals(rd.getString("HOUR20"))?false:true);
				calendarItem.setHour21("0".equals(rd.getString("HOUR21"))?false:true);
				calendarItem.setHour22("0".equals(rd.getString("HOUR22"))?false:true);
				calendarItem.setHour23("0".equals(rd.getString("HOUR23"))?false:true);
				results.add(calendarItem);
			}
			
			return results;
		}
		catch(Exception e){
			throw e;
		}
	}

}
